#include "xd3d9Surface.h"


namespace XE
{

	xd3d9Surface::xd3d9Surface(LPDIRECT3DSURFACE9 pSurface)
		:xSurface(),m_pSurface(pSurface)
	{
		if(pSurface==NULL)
	           return ;

		D3DSURFACE_DESC des;
		ZeroMemory(&des,sizeof(des));
		if(SUCCEEDED(pSurface->GetDesc(&des)))
		{
			m_width = des.Width;
			m_height = des.Height;
			m_Pool = des.Pool;
			m_Format  =des.Format;
			
		}


	}

	xd3d9Surface::~xd3d9Surface()
	{

		SafeRelease(m_pSurface);
	}


	void* xd3d9Surface::Lock(int&Pitch)
	{
		if(m_pSurface==NULL)
			return NULL;

		D3DLOCKED_RECT rect;
		if(FAILED(m_pSurface->LockRect(&rect,NULL,D3DLOCK_DISCARD)))
			return NULL;
		Pitch = rect.Pitch;
		return rect.pBits;
	}
	void xd3d9Surface::UnLock()
	{
		m_pSurface->UnlockRect();
	}



}